package org.qsoft.ext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kk
 *
 */
public class TreeNode {

	private int id;
	private String text;
	private boolean leaf;
	private String cls;
	private String icon;
	private String model;
	private String action;
	private String name;
	private String path;
	private int[] level = new int[0];
	private List children = new ArrayList();

	public TreeNode() {
	}

	public TreeNode(int id, String text, String name, int[] level,
			boolean leaf, String cls, String icon, String model, String action) {
		this.id = id;
		this.text = text;
		this.leaf = leaf;
		this.cls = cls;
		this.icon = icon;
		this.model = model;
		this.action = action;
		this.name = name;
		this.level = level;
		this.path = path;
	}
    public String getIcon(){
    	return icon;
    }
    public void setIcon(String icon){
    	this.icon=icon;
    }
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public boolean isLeaf() {

		// return leaf;

		return this.getChildren().size() == 0;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public String getCls() {
		return cls;
	}

	public void setCls(String cls) {
		this.cls = cls;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public List getChildren() {
		return children;
	}

	public void setChildren(List children) {
		this.children = children;
	}

	public String toString() {

		StringBuffer sb = new StringBuffer();

		sb.append("{");
		sb.append(format("id", this.id + ""));
		sb.append(",");
		sb.append(format("text", this.text));
		sb.append(",");
		sb.append(format("name", this.name));
		sb.append(",");
		sb.append(format("level", this.level + ""));
		sb.append(",");
		sb.append(format("leaf", this.leaf));
		sb.append(",");
		sb.append(format("cls", this.cls));
		sb.append(",");
		sb.append(format("icon", this.icon));
		sb.append(",");
		sb.append(format("model", this.model));
		sb.append(",");
		sb.append(format("path", this.path));
		sb.append(",");
		sb.append(format("action", this.action));
	 
		sb.append("}");
		return sb.toString();
	}

	private Object format(String name, String value) {

		return "\"" + name + "\":\"" + value + "\"";
	}

	private Object format(String name, boolean value) {

		return "\"" + name + "\":" + value + "";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int[] getLevel() {
		return level;
	}

	public void setLevel(int[] level) {
		this.level = level;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

}
